﻿using System.Collections.Generic;
using Protocol.Dto.Fight;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI._2.Fight
{
    public class UpPanel : UIBase
    {
        private void Awake()
        {
            Bind(UIEvent.SET_TABLE_CARDS);
        }

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case UIEvent.SET_TABLE_CARDS:
                    SetTableCards(message as List<CardDto>);
                    break;
            }
        }

        /// <summary>
        /// 底牌图片
        /// </summary>
        private Image[] imgCards;

        private void Start()
        {
            // 获取对象
            imgCards = new Image[3];
            imgCards[0] = transform.Find("Card1").GetComponent<Image>();
            imgCards[1] = transform.Find("Card2").GetComponent<Image>();
            imgCards[2] = transform.Find("Card3").GetComponent<Image>();
        }

        /// <summary>
        /// 设置底牌
        /// 卡牌的数据类 还没有定义 用object代替
        /// </summary>
        /// <param name="cards"></param>
        private void SetTableCards(List<CardDto> cards)
        {
            imgCards[0].sprite = Resources.Load<Sprite>("Poker/" + cards[0].Name);
            imgCards[1].sprite = Resources.Load<Sprite>("Poker/" + cards[1].Name);
            imgCards[2].sprite = Resources.Load<Sprite>("Poker/" + cards[2].Name);
        }
    }
}